/***************************************************************************
 创建者: 华磊
 开始时间: 2018.8.14
 copyright: (C) 华友高科
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) hualei 2017.5.8 类的具体实现代码编写

 ***************************************************************************
 *  @file modbus485driver.h
 *  功能: 超声波传感器的设置和数据获取
 *
 *                                                                         *
 ***************************************************************************/
#ifndef MODBUS485DERVER_H
#define MODBUS485DERVER_H

#include "modbus.h"
#include <qmap.h>
#include "modbusdriverconfig.h"
#include "ecattype.h"


class ModbusDriverConfig;
/**
 * @brief The Modbus485Driver class 驱动类
 */
class Modbus485Driver
{
public:
    Modbus485Driver(QString fileName, int modbusIdIn, int* globalCurrentAliasIn,
                        modbus_t* globalCurrentModbusMasterIn);
    ~Modbus485Driver();

public:

    int getModbusMaster(modbus_t* modbusMasterReturn);
//    int setModbusMaster(modbus_t* modbusMasterIn);
    int servOnDriver();
    int servOffDriver();
    int quickStopDriver();

    int setDriverMode(E_MOTOR_CONTROL_MODE modeIn);
    int setPosition(int positionIn);
    int setPwm(int pwmIn);
    int setSpeed(int speedIn);
    int setMaxCurrency(double ample);
    int setRatedCurrency(double ample);
    int changeDriverModbusId(int modbusId_new);

    int getErrorCode( int& errorCodeReturn);
    int getPositionFeedback(int& positionFeedback);
    int setControlWord(int controlWordIn);
    int getStatusWord(int& statusWordReturn);
    int getSpeedFeedback(double &speedFeedback);
    int getCurrencyFeedback(double &currencyFeedback);
    int initialDriverParameter();
    int connectPort();
    bool isInitialOkStatus();
    int checkModbusMaster();

protected:


    int initial(QString fileName);


private:
    int* globalCurrentAlias;
    modbus_t* globalCurrentModbusMaster;

    ModbusDriverConfig* driverConfig;
    modbus_t* modbusMaster;
    int modbusId;
    bool isInitialedOk;

    CommunicateParameter comParameter;
    RegConfig regConfig;
    RegAddressInfo regAdd;
    E_VENDOR_ID vendorId;

    E_MOTOR_CMD controlWord;


};

#endif // MODBUS485DERVER_H
